﻿using Sidvall.IO;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace Sidvall.Web.IO
{
    public class FileSystemEntryManager
    {
        #region Public Members

        #region GetFileSystemEntryNamesAsync

        public async Task<IEnumerable<string>> GetFileSystemEntryNamesAsync(string storeId, string path, string searchPattern, SearchOption searchOption, CancellationToken cancellationToken)
        {
            var store = Sidvall.Web.IO.SystemContext.Current.FileSystemContext.Stores.FindStore(storeId);
            await SystemContext.Current.ThrowIfNotAuthorizedAsync(store, Sidvall.IO.Security.DomainObjects.FileSystemEntry, Sidvall.Security.Operations.GetItemsMetadata, path).ConfigureAwait(false);
            var fs = await SystemContext.Current.FileSystemFactory.CreateAsync(store).ConfigureAwait(false);
            return await fs.GetFileSystemEntryNamesAsync(path, searchPattern, searchOption, cancellationToken).ConfigureAwait(false);
        }

        #endregion

        #endregion
    }
}
